using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_LeaveWord {
		#region Fields
		private int id;
		private int elementId;
		private int uid;
		private string leaveWords;
		private DateTime keyin_date = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private string elementType;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_LeaveWord class.
		/// </summary>
		public TF_LeaveWord() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_LeaveWord class.
		/// </summary>
		public TF_LeaveWord(int elementId, int uid, string leaveWords, DateTime keyin_date, string elementType) {
			this.elementId = elementId;
			this.uid = uid;
			this.leaveWords = leaveWords;
			this.keyin_date = keyin_date;
			this.elementType = elementType;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_LeaveWord class.
		/// </summary>
		public TF_LeaveWord(int id, int elementId, int uid, string leaveWords, DateTime keyin_date, string elementType) {
			this.id = id;
			this.elementId = elementId;
			this.uid = uid;
			this.leaveWords = leaveWords;
			this.keyin_date = keyin_date;
			this.elementType = elementType;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the ElementId value.
		/// </summary>
		public int ElementId {
			get { return elementId; }
			set { elementId = value; }
		}
		
		/// <summary>
		/// Gets or sets the Uid value.
		/// </summary>
		public int Uid {
			get { return uid; }
			set { uid = value; }
		}
		
		/// <summary>
		/// Gets or sets the LeaveWords value.
		/// </summary>
		public string LeaveWords {
			get { return leaveWords; }
			set { leaveWords = value; }
		}
		
		/// <summary>
		/// Gets or sets the Keyin_date value.
		/// </summary>
		public DateTime Keyin_date {
			get { return keyin_date; }
			set { keyin_date = value; }
		}
		
		/// <summary>
		/// Gets or sets the ElementType value.
		/// </summary>
		public string ElementType {
			get { return elementType; }
			set { elementType = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_LeaveWords table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_LeaveWordsInsert", elementId, uid, leaveWords, keyin_date, elementType));
		}
		
		/// <summary>
		/// Updates a record in the TF_LeaveWords table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_LeaveWordsUpdate", id, elementId, uid, leaveWords, keyin_date, elementType);
		}
		
		/// <summary>
		/// Deletes a record from the TF_LeaveWords table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_LeaveWordsDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the TF_LeaveWords table.
		/// </summary>
		public static TF_LeaveWord Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_LeaveWordsSelect", id)) {
				if (dataReader.Read()) {
					return MakeTF_LeaveWord(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_LeaveWords table.
		/// </summary>
		public static List<TF_LeaveWord> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_LeaveWordsSelectAll")) {
				List<TF_LeaveWord> tF_LeaveWordList = new List<TF_LeaveWord>();
				while (dataReader.Read()) {
					TF_LeaveWord tF_LeaveWord = MakeTF_LeaveWord(dataReader);
					tF_LeaveWordList.Add(tF_LeaveWord);
				}
				return tF_LeaveWordList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_LeaveWords class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_LeaveWord MakeTF_LeaveWord(SqlDataReader dataReader) {
			TF_LeaveWord tF_LeaveWord = new TF_LeaveWord();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_LeaveWord.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_LeaveWord.ElementId = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_LeaveWord.Uid = dataReader.GetInt32(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_LeaveWord.LeaveWords = dataReader.GetString(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_LeaveWord.Keyin_date = dataReader.GetDateTime(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tF_LeaveWord.ElementType = dataReader.GetString(5);
			}

			return tF_LeaveWord;
		}
		#endregion
	}
}
